//
//  LGTitleView.m
//  微博
//
//  Created by MS on 15-12-4.
//  Copyright (c) 2015年 MS. All rights reserved.
//

#import "LGTitleView.h"
#import "UIImage+Image.h"
@implementation LGTitleView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {

        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [self setBackgroundImage:[UIImage imageResizingWithName:@"navigationbar_filter_background_highlighted"] forState:UIControlStateHighlighted];
    }
    
    return self;
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    if (self.currentImage==nil) {
        return;
    }
    
    //title
    self.titleLabel.x = 0;
    
    //image
    self.imageView.x = CGRectGetMaxX(self.titleLabel.frame);
 
    
    
}


//重写set方法，扩展计算尺寸
-(void) setTitle:(NSString *)title forState:(UIControlState)state
{
    [super setTitle:title forState:state];
    
    [self sizeToFit];
    
}

-(void) setImage:(UIImage *)image forState:(UIControlState)state
{
    
    [super setImage:image forState:state];
    
    [self sizeToFit];
    
}


@end
